package com.usc.pys7.controllers;

import lombok.extern.java.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
@Log
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity <ResponseResult> handleRuntimeException(RuntimeException ex){
        ex.printStackTrace();
        return new ResponseEntity<>(
              ResponseResult.error("服务器出现运行错误，有可能是参数类型错误"+ex.getMessage()),
                HttpStatus.BAD_REQUEST
        );
    }
    @ExceptionHandler(Exception.class)
    public ResponseEntity<ResponseResult> handleRuntimeException(Exception ex){
        ex.printStackTrace();
        return new ResponseEntity<>(
                ResponseResult.error("服务器出现致命错误"+ex.getMessage()),
                HttpStatus.INSUFFICIENT_STORAGE
        );
    }
}